package com.qk.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.qk.commom.PageResult;
import com.qk.entity.Course;
import com.qk.mapper.CourseMapper;
import com.qk.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class CourseServiceImpl implements CourseService {
    @Autowired
    private CourseMapper courseMapper;
    @Override
    public PageResult<Course> list(String name, Integer subject, Integer target, Integer page, Integer pageSize) {
        PageHelper.startPage(page,pageSize);
        List<Course> courseList=courseMapper.selectAll(name,subject,target);
        Page< Course> p=(Page<Course>)(courseList);
        return new PageResult<>(p.getTotal(),p.getResult());
    }

    @Override
    public void deleteById(Integer id) {
        courseMapper.deleteById(id);
    }

    @Override
    public void add(Course course) {
        course.setCreateTime(LocalDateTime.now());
        course.setUpdateTime(LocalDateTime.now());
        courseMapper.add(course);
    }

    @Override
    public Course findById(Integer id) {
        return courseMapper.findById(id);
    }

    @Override
    public void update2(Course course) {
        course.setUpdateTime(LocalDateTime.now());
        courseMapper.update2(course);
    }

    @Override
    public List<Course> listCourse() {
        return courseMapper.listCourse();
    }

    @Override
    public List<Course> findBySubject(Integer subject) {
        return courseMapper.findBySubject(subject);
    }
}
